package com.huxi.lang.exception;

import java.util.Objects;

/**
 * 文本解析异常
 * 
 * @since 1.0
 * @version 1.0
 * @author jian.wu
 *
 */
public class ValueParseException extends ValueException {

	private static final long serialVersionUID = 1L;
	private static final String pattern = "[%s] parse text failed - %s";

	private final Class<?> castType;
	private final CharSequence value;

	public ValueParseException(Class<?> dataType, CharSequence source, Throwable throwable) {
		super(String.format(pattern, dataType, throwable.getMessage()), throwable);
		this.castType = Objects.requireNonNull(dataType);
		this.value = source;
	}

	public ValueParseException(Class<?> dataType, CharSequence source, String message) {
		super(String.format(pattern, dataType, message));
		this.castType = Objects.requireNonNull(dataType);
		this.value = source;
	}

	@Override
	public CharSequence getValue() {
		return value;
	}

	public Class<?> getCastType() {
		return castType;
	}

}
